<?php
namespace App\Logic\World;

use App\Logic\Logic;
use App\Model\Message\MessageBean;
use App\Model\User\UserBean;
use EasySwoole\Core\Utility\Random;
use EasySwoole\Core\Swoole\Task\TaskManager;
use App\Server\Task\WorldMessageTask;

class WorldLogic extends Logic
{

    function sendMsgToWorld(UserBean $myinfo, $message)
    {
        $messageId = Random::randStr(3) . Random::randStr(3) . Random::randNumStr(5);
        $mb = new MessageBean();
        $mb->setAddtime(time());
        $mb->setContent($message);
        $mb->setFromid($myinfo->getUid());
        $mb->setId($messageId);
        $mb->setType(MessageBean::WORLD_CHAT_TYPE);
        $mb->setUid(0);
        
        TaskManager::async((new WorldMessageTask([
            "userinfo" => $myinfo->objToArray(true),
            'msg' => $mb->objToArray(true)
        ])));
    }
}